﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Phone
{
    //设置界面
    public partial class Settings : Form
    {
        //默认构造函数
        public Settings()
        {
            InitializeComponent();
        }

        //窗体加载时读取设置并显示
        private void Settings_Load(object sender, EventArgs e)
        {
            if (Vars.settings[0] == 1)
            {
                checkBox1.Checked = true;
            }
            if (Vars.settings[1] == 1)
            {
                checkBox2.Checked = true;
            }
            if (Vars.settings[0] == 0)
            {
                checkBox2.Enabled = false;
                button2.Enabled = false;
                button3.Enabled = false;
            }
        }

        //窗体关闭时退出程序
        private void Settings_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (Form.ActiveForm == this) Application.Exit();
        }

        //返回主界面
        private void button1_Click(object sender, EventArgs e)
        {
            MainForm mainForm = Application.OpenForms.OfType<MainForm>().FirstOrDefault();
            mainForm.Show();
            mainForm.Location = this.Location;
            this.Close();
        }

        //打开地址簿界面
        private void button2_Click(object sender, EventArgs e)
        {
            Addresses addresses = new Addresses();
            addresses.Show();
            addresses.Location = this.Location;
            this.Close();
        }

        //打开自定义信号设置界面
        private void button3_Click(object sender, EventArgs e)
        {
            Signals signals = new Signals();
            signals.Show();
            signals.Location = this.Location;
            this.Close();
        }

        //打开/关闭报警辅助功能
        private void checkBox1_Click(object sender, EventArgs e)
        {
            Vars.settings[0] = 1 - Vars.settings[0];
            if (Vars.settings[0] == 1)
            {
                checkBox2.Enabled = true;
                button2.Enabled = true;
                button3.Enabled = true;
            }
            else
            {
                checkBox2.Enabled = false;
                button2.Enabled = false;
                button3.Enabled = false;
            }
        }

        //打开/关闭自动发送GPS功能
        private void checkBox2_Click(object sender, EventArgs e)
        {
            Vars.settings[1] = 1 - Vars.settings[1];
        }

        private void button4_Click(object sender, EventArgs e)
        {
            Login login = new Login();
            login.Show();
            login.Location = this.Location;
            this.Close();
        }
    }
}
